<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  mail.php
//  phpweb
//  
//  Created by WillLee on 2011-08-01.
//  Copyright 2011 lishuzu. All rights reserved.
// 

/*
*邮件提醒
*/
class Mail extends CI_Controller {

	 function __construct()
	 {
		parent::__construct();
		$this->load->database();
	 }

	 function notice()
	 {
		$this->db->select('uid, username, name, status, newpm, notenum, mailnotice');
		$where = array('notenum >' => '0', 'status'=>'0');
		$this->db->where($where);
		$query = $this->db->get('user');
		foreach ($query->result_array() as $value) {
			if ($value['mailnotice']) {
				//邮件内容
		 		$this->load->model('common/mail_model');
		 		$this->load->model('notification_model');

				$data = array();
				$data['notices'] = $this->notification_model->get_notices($value['uid'], 20, '', 1);
				$data['message'] = "Hi ".$value['name']." 你有一阵子没有来 <a href='".base_url()."' target='_blank'>TDAYE社区 </a>了。这些都是你不在的时候收到的提醒（<span style='color: #0099FF;'>".$value['notenum']."</span>）。<br><hr>";
				
				$html = $this->load->template('mailnotice_tpl', $data, true);
				echo $html;
				exit;
				$maildata = array(
								'mailTo' => $value['username'],
								'mailFrom' => 'hi@tdaye.com',
								'displayName' => 'TDAYE',
								'mailSubject' => 'TDAYE社区提醒您 ：'.$value['name'].'您有'.$value['notenum'].'个提醒',
								'mailMessage' => $html
					);
				if ($this->mail_model->sendMail($maildata, 'html')) {
					$logstr = "uid:".$value['uid'].";msg:发送成功;";
					writelog('mail_notice', $logstr);
				}else {
					$logstr = "uid:".$value['uid'].";msg:发送失败;";
					writelog('mail_notice', $logstr);
				}
			}
		}
	 }
}
?>